import os
import cv2

img = cv2.imread('../data/beijing.jpg')
img = cv2.resize(img, (400, 500))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 简单阈值处理
# ret , thresh =cv2.threshold(img,140,255,cv2.THRESH_BINARY)

# 自适应的阈值处理
# 255 满足条件时赋予最大值 白色
# cv2.ADAPTIVE_THRESH_GAUSSIAN_C  自适应的阈值  基于像素周围区域的高斯 加权平均值计算
# 15 邻域快的大小 10 从阈值中减去的常数
thresh = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 21, 10)

cv2.imshow('img', img)
cv2.imshow('thresh', thresh)
cv2.waitKey(0)
